<template>
  <main-comp :alternate="alternate" v-if="show">
    <div class="m-mail-open" :style="mailAni">
      <div class="title" :style="animation('fadeIn', 1, 3, 1.3, 'normal', 'linear')"></div>
      <div class="title-bottom" :style="animation('fadeIn', 1, 3, 1.3, 'normal', 'linear')"></div>
      <div class="logo" :style="animation('fadeIn', 1, 0.6, 0.6)"><img src="../assets/logo.png" /></div>
      <div class="paper" :style="animation('fadeIn', 1, 0.6, 0.6)"></div>
    </div>
  </main-comp>
</template>

<script>
/* eslint-disable */
import mainComp from '../comps/last-comp'
import { mapState } from 'vuex'

export default {
  data() {
    return {
      alternate: false,
      show: true
    }
  },
  components: {
    mainComp
  },
  computed: {
    ...mapState({
      up: state => state.up,
      down: state => state.down
    }),
    mailAni() {
      return this.alternate ? this.animation('fadeOut', 1, 1.1, 0) : this.animation('fadeIn', 1, 0.2, 0.3)
    },
  },
  methods: {
    animateCB (cb) {
      this.show = false
      this.$nextTick(() => {
        this.show = true
        this.alternate = true
        setTimeout(() => {
          cb && cb()
        }, 900)
      })
    }
  },
  watch: {
    down(n) {
      if (n) {
        this.animateCB(() => {
          this.$store.dispatch('prevScene')
        })
      }
    },
    up(n) {
      if (n) {
        this.animateCB(() => {
          this.$store.dispatch('nextScene')
        })
      }
    }
  }
}
</script>

<style scoped>
.m-mail-open {
  background: url('../assets/mail_open.png') no-repeat;
  background-size: 100% 100%;
  position: absolute;
  width: 7.38rem;
  height: 11rem; 
  top: 50%;
  left: 50%;
  transform: translate(-50%, -50%);
}
.paper {
  background: url('../assets/mail_paper.png') no-repeat;
  background-size: 100% 100%;
  position: absolute;
  width: 6.41rem;
  height: 8.65rem;
  top: 1.47rem;
  z-index: 1;
  left: 0.5rem;
}
.m-mail-open .title {
  position: relative;
  z-index: 2;
  width: 4.28rem;
  height: 0.69rem;
  margin-top: 4.64rem;
  margin-left: 1.31rem;
  background: url("../assets/2/title.png") no-repeat;
  background-size: 4.28rem 1.29rem;
}
.m-mail-open .title-bottom {
  position: relative;
  z-index: 2;
  width: 4.28rem;
  height: 0.6rem;
  margin-left: 1.31rem;
  background: url("../assets/2/title.png") center bottom no-repeat;
  background-size: 4.28rem 1.29rem;
}
.m-mail-open .logo {
  position: relative;
  z-index: 2;
  width: 3.4rem;
  height: 0.47rem;
  margin-top: 2.92rem;
  margin-left: 2rem;
}
.m-mail-open img {
  width: 100%;
  height: 100%;
  display: block;
}
</style>
